package com.COMP3111H.project;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class SearchNotFound extends Activity {
	final int HELP = 0;
	Button menu;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_not_found);
		
		Button sell = (Button)findViewById(R.id.snf_sell);
		Button cancel = (Button)findViewById(R.id.snf_cancel);
		sell.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				Intent i = new Intent(SearchNotFound.this, SellLend_New_Book.class);
				startActivity(i);
			}
		});
		cancel.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				Intent i = new Intent(SearchNotFound.this, Search.class);
				startActivity(i);
			}
		});
		menu = (Button) findViewById(R.id.search_not_found_menu);
	}
	
	@Override
    protected void onResume() {
		super.onResume();
		if (LoginUtility.checkLoginStatus(this)) {
			menu.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					 String[] choices={"Home","View My Profile","Help","Cancel"};  
					             AlertDialog dialog = new AlertDialog.Builder(SearchNotFound.this)  
					                     // .setIcon(android.R.drawable.btn_star)  
					                      .setTitle("Menu")  
					                      .setItems(choices, onselect_logged).create();  
					             dialog.show();  
				}
			});
		}
		else{
			menu.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					 String[] choices={"Home","Help","Cancel"};  
					             AlertDialog dialog = new AlertDialog.Builder(SearchNotFound.this)  
					                     // .setIcon(android.R.drawable.btn_star)  
					                      .setTitle("Menu")  
					                      .setItems(choices, onselect_not_logged).create();  
					             dialog.show();  
				}
			});
		}
	}

	OnClickListener onselect_logged = new OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			Intent myIntent;
			switch (which) {
			case 0:
				myIntent = new Intent(SearchNotFound.this, Home.class);
				startActivity(myIntent);
				break;
			case 1:
				myIntent = new Intent(SearchNotFound.this, My_Profile.class);
				startActivity(myIntent);
				break;
			case 2:
				myIntent = new Intent(SearchNotFound.this, Help.class);
				startActivity(myIntent);
				break;
			case 3:
				dialog.dismiss();
				break;
			}
		}
	};
	
	OnClickListener onselect_not_logged = new OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			Intent myIntent;
			switch (which) {
			case 0:
				myIntent = new Intent(SearchNotFound.this, Home.class);
				startActivity(myIntent);
				break;
			case 1:
				myIntent = new Intent(SearchNotFound.this, Help.class);
				startActivity(myIntent);
				break;
			case 2:
				dialog.dismiss();
				break;
			}
		}
	};
}
